package com.hexinfo.dmpro.monitor.controller;

import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import com.hexinfo.dmpro.common.annotation.Log;
import com.hexinfo.dmpro.monitor.task.MonitorTask;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/apiMonitorTasks")
public class ApiMonitorTasksController {

    @Resource
    private MonitorTask monitorTask;

    @AnonymousAccess
    @Log("IMPALA执行任务同步")
    @GetMapping("/impalaAppTask")
    public ResponseEntity<Object> impalaAppTask(){
        monitorTask.impalaAppTask("6");
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @AnonymousAccess
    @Log("大数据组件状态监控")
    @GetMapping("/cmStateTask")
    public ResponseEntity<Object> cmStateTask(){
        monitorTask.cmStateTask();
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @AnonymousAccess
    @Log("yarn 集群的信息")
    @GetMapping("/getYarnMetrics")
    public ResponseEntity<Object> getYarnMetrics(){
        monitorTask.getYarnMetrics();
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @AnonymousAccess
    @Log("YARN执行任务同步")
    @GetMapping("/yarnAppTask")
    public ResponseEntity<Object> yarnAppTask(){
        monitorTask.yarnAppTask("6");
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @AnonymousAccess
    @Log("YARN队列资源同步")
    @GetMapping("/yarnSchedulerTask")
    public ResponseEntity<Object> yarnSchedulerTask(){
        monitorTask.yarnSchedulerTask();
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @AnonymousAccess
    @Log("HDFS资源同步")
    @GetMapping("/hdfsResourceTask")
    public ResponseEntity<Object> hdfsResourceTask(){
        monitorTask.hdfsResourceTask();
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @AnonymousAccess
    @Log("IMPALA资源池使用同步")
    @GetMapping("/impalaPoolTask")
    public ResponseEntity<Object> impalaPoolTask(){
        monitorTask.impalaPoolTask();
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @AnonymousAccess
    @Log("集群主机信息同步")
    @GetMapping("/clusterHostTask")
    public ResponseEntity<Object> clusterHostTask(){
        monitorTask.clusterHostTask();
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

}
